// const { Server } = require("socket.io");
// const express = require('express')
// const { createServer } = require("http"); 


// const app = express();
// const httpServer = createServer(app);
// const io = new Server(httpServer, { /* options */ });

// io.on("connection", (socket) => {
//   // ...
//   console.log(socket.id);

// });

// httpServer.listen(3000);

var ws = require('nodejs-websocket');
var server = ws.createServer(function(socket){
// 事件名称为text(读取字符串时，就叫做text)，读取客户端传来的字符串
　  var count = 1;
    socket.on('text', function(data) {
　　     // 在控制台输出前端传来的消息　　
        console.log(data);
        //向前端回复消息
        socket.sendText('Message from server side!');
    });
    socket.on('close', function(code, reason) {
        console.log('Service closed:' + reason);
    })
    connection.on('error', (err) => {
        console.log('Service Exception:' + err);
    })
}).listen(3000);

